package com.atguigu.e_map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo {
    public static void main(String[] args) {
        //创建双列集合对象
        Map<String, String> map = new HashMap<>();

        System.out.println("map = " + map);//{}

        //添加
        System.out.println("map.put(\"奶量\",\"璐璐\") = " + map.put("奶量", "璐璐"));
        map.put("暴强","蓉蓉");
        map.put("宇帆","白盒");

        //修改
        System.out.println("map.put(\"暴强\",\"网红\") = " + map.put("暴强", "网红"));

        //删除
        //根据键删除
        System.out.println("map.remove(\"暴强\") = " + map.remove("暴强"));//网红

        //根据键值删
        map.remove("宇帆","白盒");

        System.out.println("map = " + map);

        //查询
        System.out.println("map.get(\"奶量\") = " + map.get("奶量"));//璐璐

        //长度
        System.out.println("map.size() = " + map.size());//1

        //查询是否包含
        System.out.println("map.containsKey(\"奶量\") = " + map.containsKey("奶量"));//true
        System.out.println("map.containsValue(\"张曼玉\") = " + map.containsValue("张曼玉"));//false

        System.out.println("map = " + map);

        //添加一对元素
        map.put("王晓菲","大S");

        //获取键集
        Set<String> keys = map.keySet();
        System.out.println("keys = " + keys);
        System.out.println("keys.getClass() = " + keys.getClass());//java.util.HashMap$KeySet
        //获取值集
        Collection<String> values = map.values();
        System.out.println("values = " + values);
        System.out.println("values.getClass() = " + values.getClass());//java.util.HashMap$Values
    }
}
